<?php

/**
 * 提交反馈
 */

namespace app\member\api;

use \app\member\api\MemberApi;

class FeedbackApi extends MemberApi {

    /**
     * 提交反馈
     */
    public function push() {

        $model = target('member/MemberFeedback');

        $t = time();
        $start = mktime(0, 0, 0, date("m", $t), date("d", $t), date("Y", $t));
        $end = mktime(23, 59, 59, date("m", $t), date("d", $t), date("Y", $t));
        $count = $model->countList([
            'A.user_id' => $this->userId,
            '_sql' => 'A.time <' . $end . ' AMD A.time > ' . $start
        ]);

        if($count >= 10) {
            $this->error('当天反馈数量不能超过10条！');
        }

        $content = $this->data['content'];
        $content = html_clear($content);

        if (mb_strlen($content) < 10) {
            $this->error('反馈内容不能小于10个字符！');
        }

        if (mb_strlen($content) > 250) {
            $this->error('反馈内容不能大于250个字！');
        }

        $status = $model->add([
            'time' => time(),
            'user_id' => $this->userId,
            'content' => $content
        ]);

        if (!$status) {
            $this->error('提交反馈失败');
        }
        $this->success('ok');


    }

}